<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/1/4 0004
  Time: 13:55
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>公告</title>
    <jsp:include page="/commons/common-js.jsp"></jsp:include>
</head>
<body>

<table class="layui-hide" id="bulletintable" lay-filter="bulletintable"></table>

<form class="layui-form" id="bullform" style="display: none;padding: 20px 20px 20px 20px" action="" lay-filter="bulletinform">

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">标题</label>
        <div class="layui-input-inline">
            <input type="text" name="head" autocomplete="off" class="layui-input"/>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">正文</label>
        <div class="layui-input-block">
            <textarea name="body" autocomplete="off" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">结尾</label>
        <div class="layui-input-inline">
            <input type="foot" name="foot" autocomplete="off" class="layui-input"/>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">起始vip</label>
        <div class="layui-input-inline">
            <input type="foot" name="fromVip" autocomplete="off" class="layui-input" value="0" />
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">终止vip</label>
        <div class="layui-input-inline">
            <input type="foot" name="toVip" autocomplete="off" class="layui-input" value="99"/>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">层级</label>
        <div class="layui-input-inline">
            <input type="foot" name="layer" autocomplete="off" class="layui-input" value="99"/>
        </div>
    </div>

</form>


<script type="text/html" id="addbulletin">
    <div class="layui-inline">
        <button class="layui-btn layui-btn-sm" lay-event="add">新增</button>
    </div>
</script>

<script type="text/html" id="statetemplet">
    {{# if(d.state==1){ }}
    <span>开启</span>
    {{# }else { }}
    <span>关闭</span>
    {{# } }}
</script>

<script type="text/html" id="statescript">
    <button class="layui-btn layui-btn-xs" lay-event="state">开启/关闭</button>
</script>

<script>
    layui.use(['form', 'table'], function(){
        var form = layui.form,
            table = layui.table,
            laytpl = layui.laytpl



        var tableins = table.render({
            elem: '#bulletintable'
            , url: '/sys/bulletin'
            , defaultToolbar: []
            , autoSort: false
            , toolbar: '#addbulletin'
            , cols: [[
                {field: 'id', width: 60, title: '标识'}
                , {field: 'head', width: 100, title: '头'}
                , {field: 'body', width: 500, title: '身'}
                , {field: 'foot', width: 100, title: '脚'}
                , {field: 'fromVip', width: 100, title: '起始vip'}
                , {field: 'toVip', width: 100, title: '终止vip'}
                , {field: 'layer', width: 60, title: '层级'}
                , {field: 'state', width: 60, title: '状态', templet: '#statetemplet'}
                , {field: 'clo', width: 90, title: '调整', templet: '#statescript'}
            ]]
            , page: true
            , limits: [50, 100, 150]
            , limit: 50
            , height: '800',
        });

        //头工具栏事件
        table.on('toolbar(bulletintable)', function(obj){
            switch(obj.event){
                case 'add' :
                    //页面层
                    $("#bullform")[0].reset();
                    layer.open({
                        type: 1,
                        skin: 'layui-layer-rim', //加上边框
                        content: $("#bullform"),
                        area: ['800px', '500px'], //宽高
                        btn:['保存','取消'],
                        yes:function (index,layero) {
                            var data = form.val("bulletinform");
                            $.ajax({
                                url:"/sys/upbulletin",
                                data:data,
                                success:function(res){
                                    layer.msg(res.msg);
                                    tableins.reload();
                                    layer.close(index);
                                }
                            })
                        },
                        no:function (index,layero) {
                            layer.close(index);
                        }
                    });

                    break;
            };
        });

        //行工具栏事件
        table.on('tool(bulletintable)', function(obj){

            switch(obj.event){
                case 'state' :

                    $.ajax({
                        url:"/sys/bulletinstate/"+obj.data.id+"/"+obj.data.state,
                        success:function(res){
                            layer.msg(res.msg);
                            tableins.reload();
                        }
                    })
                    break;
            };
        });

    });
</script>
</body>
</html>
